import {
	API_HOST,
	API_PROXY
} from "../config.js"

/**
 * 组装接口url
 */
export const packApiUrl = (url = '') => {
	if (url.slice(0, 4) === 'http') return url
	else return `${API_HOST}${API_PROXY}${url}`
}

//时间
export function timeSince(timestamp) {
	const now = new Date();
	const diff = now - timestamp;

	if (diff < 1000 * 60) {
		return '一分钟内';
	} else if (diff < 1000 * 60 * 60 * 24) {
		return Math.floor(diff / (1000 * 60 * 60)) + ' 小时前';
	} else if (diff < 1000 * 60 * 60 * 24 * 30) {
		return Math.floor(diff / (1000 * 60 * 60 * 24)) + ' 天前';
	} else if (diff < 1000 * 60 * 60 * 24 * 30 * 12) {
		return Math.floor(diff / (1000 * 60 * 60 * 24 * 30)) + ' 个月前';
	} else {
		return null;
	}
}


export function gotoHome() {
	uni.showModal({
		title: "提示",
		content: "页面有误返回首页",
		showCancel: false,
		success: (res) => {
			if (res.confirm) {
				uni.reLaunch({
					url: "/pages/index/index"
				})
			}

		}
	})
}